package com.yc.navy.dayfresh.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yc.navy.dayfresh.bean.ProductInfo;
import com.yc.navy.dayfresh.dto.SalesInfoDTO;
import com.yc.navy.dayfresh.mapper.IProductInfoMapper;
import com.yc.navy.dayfresh.mapper.ITypeInfoMapper;
import com.yc.navy.dayfresh.service.IProductInfoService;
import com.yc.navy.dayfresh.util.FindByPageParamUtil;
import com.yc.navy.dayfresh.util.StringUtil;

@Service
public class ProductInfoServiceImpl implements IProductInfoService {
	@Autowired
	private IProductInfoMapper productInfoMapper;
	
	@Autowired
	private ITypeInfoMapper typeInfoMapper;
	
	@Override
	public int add(ProductInfo pf) {
		if(StringUtil.checkNull(pf.getPname(),pf.getPrice(),pf.getPics())) {
			return -1;
		}
		return productInfoMapper.add(pf);
	}

	@Override
	public List<ProductInfo> findByPage(Map<String, Object> map) {
		return productInfoMapper.findByPage(FindByPageParamUtil.findByPageParam(map));
	}

	@Override
	public int total(Map<String, Object> map) {
		return productInfoMapper.total(map);
	}

	@Override
	public int updataStores(String[] cnos) {
		return productInfoMapper.updataStores(cnos);
	}

	@Override
	public ProductInfo findByPno(String pno) {
		return productInfoMapper.findByPno(pno);
	}

	@Override
	public Map<String,Object> findIndex() {
		Map<String,Object > result = new HashMap<String , Object> ();
		result.put("code",200);
		result.put("types",typeInfoMapper.finds());
		result.put("products",productInfoMapper.findIndex());
		return result;
	}

	@Override
	public Map<String, Object> findFirstByPage(Map<String, Object> map){
		Map<String , Object> result = new HashMap<String, Object>();
		System.out.println("findFirstByPage->map===" + map);
		result.put("code",200);
		result.put("rows",this.findByPage(map));
		result.put("total",productInfoMapper.total(map));
		System.out.println("findFirstByPage==="+result);
		return result;
	}

	@Override
	public int updateStore(List<SalesInfoDTO> list) {
		return productInfoMapper.updateStore(list);
	}

}
